/**
 * The main application class. An instance of this class is created by app.js when it calls
 * Ext.application(). This is the ideal place to handle application launch and initialization
 * details.
 */
Ext.define('tPAXXAdminDesktop.Application', {
    extend: 'Ext.app.Application',
    requires: [
        'Ext.app.Controller',
        'tPAXXAdminDesktop.System',
        'tPAXXAdminDesktop.Common.desktop.Module',
        'tPAXXAdminDesktop.Common.Module',
        'tPAXXAdminDesktop.view.main.Main'
    ],
    
    name: 'tPAXXAdminDesktop',

    stores: [
        // TODO: add global / shared stores here
    ],

    modules: [],
    dConfigs: [],
    tbConfigs: [],

    init: function() {
        
    },
    
    createViewport: function() {
        this.viewport = Ext.create('tPAXXAdminDesktop.view.main.Main', {
            modules: this.modules,
            dConfigs: this.dConfigs,
            tbConfigs: this.tbConfigs
        });
    },

    getDesktopApp: function() {
        return this.viewport;
    },

    getDesktop: function() {
        return this.getDesktopApp().getDesktop();
    },

    launch: function () {
        //to add shortcuts to desktop: this.viewport.desktop.shortcuts.add({ name: 'Grid Window', iconCls: 'grid-shortcut', module: 'grid-win' })

        // Set desktop instance as system variable
        tPAXXAdminDesktop.System.setSApp(this);

        //TODO: vorhandene Module automatisch laden
        var modules = ['tPAXXAdminDesktop.Hotel.masterdata.Module'];
        Ext.each(modules, function(m) {
            var mod = tPAXXAdminDesktop.System.application(m);
            if (mod) {
                var dConf = mod.getDesktopConfig();
                var tbConf = mod.getTaskbarConfig();
                if ((dConf || tbConf) && (mod instanceof tPAXXAdminDesktop.Common.desktop.Module)) {
                    this.modules.push(mod);
                    if (dConf) {
                        this.dConfigs.push(dConf);
                    }
                    if (tbConf) {
                        this.tbConfigs.push(tbConf);
                    }
                }
            }
        }, this);
        this.createViewport();
    }

    
});
